﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace tpcs4_cours
{
    class Vector
    {
        #region SWAP
        /// <summary>
        /// Swap a and b, but only in the function.
        /// </summary>
        public static void Swap(int a, int b)
        {
            int c = 0;
            c = a;
            a = b;
            b = c;
        }

        /// <summary>
        /// Swap a and b by reference.
        /// </summary>
        public static void Swap_ref(ref int a, ref int b)
        {
            int c = 0;
            c = a;
            a = b;
            b = c;
        }
        #endregion

        #region ARRAY
        /// <summary>
        /// Initialize an int array with fixed value.
        /// </summary>
        /// <param name="array">The int array to initialize</param>
        /// <param name="e">The element value</param>
        /// <param name="size">The size of the array</param>
        public static void Init_array(int[] array, int e, uint size)
        {
            for (int i = 0; i < size; i++)
            {
                array[i] = e;
            }
        }

        /// <summary>
        /// Initialize an int array with random value.
        /// </summary>
        /// <param name="array">The int array to initialized</param>
        /// <param name="max">The maximum value</param>
        /// <param name="seed">The random seed</param>
        /// <param name="size">The size of the array</param>
        public static void Init_rand_array(int[] array, int max, int seed, uint size)
        {
            Random r = new Random(seed);
            for (int i = 0; i < size; i++)
            {
                array[i] = r.Next(max);
            }
        }

        /// <summary>
        /// Print the content of an array.
        /// None is print if size is 0, otherwise the element are separated by a single space.
        /// </summary>
        /// <param name="array">The int array to print</param>
        /// <param name="size">The size of the array</param>
        public static void Print_array(int[] array, uint size)
        {
            for (int i = 0; i < size; i++)
            {
                Console.WriteLine(array[i]);
            }
        }

        /// <summary>
        /// Sort the elements of an array with swap (insert sort).
        /// </summary>
        /// <param name="array">The int array to sort</param>
        /// <param name="size">The size of the array</param>
        public static void Sort_swap_array(int[] array, uint size)
        {
            for (int i = 0; i < size; i++)
            {
                int x = array[i];
                int j = i;
                while (j > 0 && array[j - 1] > x)
                {
                    Swap_ref(ref array[j], ref array[j - 1]);
                    j = j - 1;
                }
                array[j] = x;
            }
        }

        /// <summary>
        /// Sort the elements of an array.
        /// </summary>
       public static void Sort_array(int[] array)
        {
            // FIX ME
        }
        #endregion
    }
}
